package com.aaa.bbb.mymaintain.service.impl;

import com.aaa.bbb.mymaintain.entity.Account;
import com.aaa.bbb.mymaintain.dao.AccountDao;
import com.aaa.bbb.mymaintain.service.AccountSer;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author max
 * @since 2023-11-03
 */
@Service
public class AccountSerImpl extends ServiceImpl<AccountDao, Account> implements AccountSer {

    @Override
    public Map<String, String> login(String userName, String password) {
        Map<String, String> map = new HashMap<>();
        int res = query().eq("username", userName).count();
        if(res == 0) {
            // 用户名不存在
            map.put("res", "-1");
            return map;
        }
        Account account = query().eq("username", userName)
                .one();
        if(password.equals(account.getPassword())) {
            // 登录成功
            map.put("res", "1");
            map.put("username", account.getUsername());
            map.put("post",baseMapper.selectPost(userName).get("post"));
            return map;
        } else {
            // 登录不成功
            map.put("res", "-2");
            return map;
        }
    }
}
